<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <title>文章管理接口文档</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            margin: 20px;
        }

        h1,
        h2,
        h3 {
            color: #333;
        }

        pre {
            background-color: #f4f4f4;
            padding: 10px;
            border-radius: 5px;
            overflow-x: auto;
        }

        code {
            background-color: #eee;
            padding: 2px 4px;
            border-radius: 3px;
        }

        table {
            border-collapse: collapse;
            width: 100%;
            margin-bottom: 20px;
        }

        th,
        td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }

        th {
            background-color: #f2f2f2;
        }
    </style>
</head>

<body>
    <h1>文章管理接口文档</h1>
    <p>本接口服务运行在服务器 <code>120.24.176.10</code>，端口为 <code>3000</code>。</p>

    <h2>1. 添加文章 (<code>/articles</code>)</h2>
    <h3>📌 接口说明</h3>
    <p>用于添加新文章，需提供标题、内容和作者，可选发布时间。</p>
    <h3>🔧 请求信息</h3>
    <ul>
        <li><strong>请求方法</strong>: <code>POST</code></li>
        <li><strong>请求 URL</strong>: <code>http://120.24.176.10:3000/articles</code></li>
        <li><strong>请求头</strong>: <code>application/json</code></li>
        <li><strong>请求体格式</strong>: JSON</li>
        <li><strong>请求参数</strong>:</li>
    </ul>
    <table>
        <tr>
            <th>参数名</th>
            <th>类型</th>
            <th>是否必填</th>
            <th>说明</th>
        </tr>
        <tr>
            <td>title</td>
            <td>String</td>
            <td>是</td>
            <td>标题</td>
        </tr>
        <tr>
            <td>content</td>
            <td>String</td>
            <td>是</td>
            <td>内容</td>
        </tr>
        <tr>
            <td>author</td>
            <td>String</td>
            <td>是</td>
            <td>作者</td>
        </tr>
        <tr>
            <td>publishedAt</td>
            <td>Date</td>
            <td>否</td>
            <td>发布时间</td>
        </tr>
    </table>
    <h3>✅ 成功响应示例</h3>
    <pre><code>{
  "code": 30000,
  "message": "文章添加成功",
  "data": {
    "id": 1,
    "title": "测试文章",
    "content": "这是内容",
    "author": "张三",
    "publishedAt": "2025-06-10T12:00:00.000Z",
    "createdAt": "2025-06-10T12:00:00.000Z"
  }
}</code></pre>
    <h3>❌ 错误响应示例</h3>
    <pre><code>{ "code": 30001, "error": "标题、内容和作者为必填项" }</code></pre>

    <hr />

    <h2>2. 获取所有文章 (<code>/articles</code>)</h2>
    <h3>📌 接口说明</h3>
    <p>获取所有文章列表。</p>
    <h3>🔧 请求信息</h3>
    <ul>
        <li><strong>请求方法</strong>: <code>GET</code></li>
        <li><strong>请求 URL</strong>: <code>http://120.24.176.10:3000/articles</code></li>
        <li><strong>请求头</strong>: 无特殊要求</li>
        <li><strong>请求参数</strong>: 无</li>
    </ul>
    <h3>✅ 成功响应示例</h3>
    <pre><code>{
  "code": 30000,
  "message": "查询成功",
  "data": [
    {
      "id": 1,
      "title": "测试文章",
      "content": "这是内容",
      "author": "张三",
      "publishedAt": "2025-06-10T12:00:00.000Z",
      "createdAt": "2025-06-10T12:00:00.000Z"
    }
  ]
}</code></pre>

    <hr />

    <h2>3. 获取单篇文章 (<code>/articles/:id</code>)</h2>
    <h3>📌 接口说明</h3>
    <p>根据文章ID获取单篇文章详情。</p>
    <h3>🔧 请求信息</h3>
    <ul>
        <li><strong>请求方法</strong>: <code>GET</code></li>
        <li><strong>请求 URL</strong>: <code>http://120.24.176.10:3000/articles/1</code></li>
        <li><strong>请求头</strong>: 无特殊要求</li>
        <li><strong>请求参数</strong>: 路径参数 <code>id</code> (文章ID)</li>
    </ul>
    <h3>✅ 成功响应示例</h3>
    <pre><code>{
  "code": 30000,
  "message": "查询成功",
  "data": {
    "id": 1,
    "title": "测试文章",
    "content": "这是内容",
    "author": "张三",
    "publishedAt": "2025-06-10T12:00:00.000Z",
    "createdAt": "2025-06-10T12:00:00.000Z"
  }
}</code></pre>
    <h3>❌ 错误响应示例</h3>
    <pre><code>{ "code": 30002, "error": "文章未找到" }</code></pre>

    <hr />

    <h2>4. 更新文章 (<code>/articles/:id</code>)</h2>
    <h3>📌 接口说明</h3>
    <p>根据ID更新文章信息，参数均为可选。</p>
    <h3>🔧 请求信息</h3>
    <ul>
        <li><strong>请求方法</strong>: <code>PUT</code></li>
        <li><strong>请求 URL</strong>: <code>http://120.24.176.10:3000/articles/1</code></li>
        <li><strong>请求头</strong>: <code>application/json</code></li>
        <li><strong>请求体格式</strong>: JSON</li>
        <li><strong>请求参数</strong>:</li>
    </ul>
    <table>
        <tr>
            <th>参数名</th>
            <th>类型</th>
            <th>是否必填</th>
            <th>说明</th>
        </tr>
        <tr>
            <td>title</td>
            <td>String</td>
            <td>否</td>
            <td>新标题</td>
        </tr>
        <tr>
            <td>content</td>
            <td>String</td>
            <td>否</td>
            <td>新内容</td>
        </tr>
        <tr>
            <td>author</td>
            <td>String</td>
            <td>否</td>
            <td>新作者</td>
        </tr>
        <tr>
            <td>publishedAt</td>
            <td>Date</td>
            <td>否</td>
            <td>新发布时间</td>
        </tr>
    </table>
    <h3>✅ 成功响应示例</h3>
    <pre><code>{
  "code": 30000,
  "message": "文章更新成功",
  "data": {
    "id": 1,
    "title": "测试文章(更新)",
    "content": "新内容",
    "author": "李四",
    "publishedAt": "2025-06-11T12:00:00.000Z",
    "createdAt": "2025-06-10T12:00:00.000Z"
  }
}</code></pre>
    <h3>❌ 错误响应示例</h3>
    <pre><code>{ "code": 30002, "error": "文章未找到" }</code></pre>

    <hr />

    <h2>业务状态码说明</h2>
    <table>
        <tr>
            <th>状态码</th>
            <th>说明</th>
        </tr>
        <tr>
            <td>30000</td>
            <td>操作成功（如添加、查询、更新等）</td>
        </tr>
        <tr>
            <td>30001</td>
            <td>参数缺失（如标题、内容或作者未填写）</td>
        </tr>
        <tr>
            <td>30002</td>
            <td>资源未找到（如指定ID的文章不存在）</td>
        </tr>
        <tr>
            <td>50000</td>
            <td>服务器内部错误</td>
        </tr>
    </table>

    <h2>通用错误返回</h2>
    <pre><code>{
  "code": 50000,
  "error": "错误信息"
}</code></pre>

    <h2>备注</h2>
    <ul>
        <li>所有接口返回均为 JSON 格式。</li>
        <li>添加和更新时，<code>title</code>、<code>content</code> 和 <code>author</code> 必填，其余字段可选。</li>
        <li>如需分页、搜索等功能可扩展。</li>
    </ul>
</body>

</html>